<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正则练习3</title>
</head>
<body>
    

</body>
</html>
    <script>
        // 使用正则表达式的方式来去除用户输入的两边的空格
        let str = prompt("请输入")
        let reg = /\s+/g
        let newStr = str.replace(reg,"")
        let removedSpaces = str.length - newStr.length
        document.write("用户输入内容去掉的空格数量为:" + removedSpaces + "<br>")
        document.write("用户输入内容去掉空格后的总长度为:" + newStr.length + "<br>")
        document.write("用户输入内容去掉两边空格后为:" + newStr)
    </script>